using System.Collections.Generic;
using VirtualDeveloper;
using VirtualDeveloper.CodeTransformation;
using Xunit;

namespace UnitTest
{
    public class DevelopOnExistingFileTest
    {
        private readonly Developer developer;

        public DevelopOnExistingFileTest()
        {
            developer = new Developer(new AddCodeToEnd());
        }

        [Fact]
        public void Add_content_at_the_end()
        {
            const string code = "hello";

            var modify = developer.Code(code, "world");
            Assert.Equal("hello world", modify);
        }

        [Fact]
        public void Add_multiple_words_at_the_end()
        {
            var dev = new Developer(new List<ILineTransformer> {new AddCodeToEnd()});
            Assert.Equal("hello world! lorem", dev.Code("hello", "world! lorem"));
        }

        [Fact]
        public void Add_words_to_every_lines()
        {
            const string code = @"hello
helo";
            const string expected = @"hello world
helo w";

            Assert.Equal(expected, developer.Code(code, "world", "w"));
        }

        [Fact]
        public void Duplicate_lines()
        {
            const string code = @"hello
hel
toto titi tata";

            const string expected = @"hello
hello
hel
hel
toto titi tata
toto titi tata";

            var target = new Developer(new DuplicateLine());

            var actual = target.Code(code);
            Assert.Equal(expected, actual);
        }

        [Fact]
        public void Replace_world_by_new()
        {
            const string code = @"hello
titi";
            const string expected = @"hello
world";
            var target = new Developer(new ReplaceCode());

            Assert.Equal(expected, target.Code(code, "world"));
        }

        [Fact]
        public void Developper_create_new_code()
        {
            var target = new Developer();

            Assert.NotEmpty(target.Code());
        }

        [Fact]
        public void Round_robin_add_to_the_end_or_the_beginning_or_both()
        {
            var target = new Developer(new AddCodeToEnd(), new AddCodeToBeginning(), new AddCodeToEndAndBeginnning());

            const string code = @"hello
helo
hel
hello
helo
hel";
            const string expected = @"hello world
toto helo
world hel world
hello toto
world helo
toto hel toto";

            Assert.Equal(expected, target.Code(code, "world", "toto"));
        }

        [Fact]
        public void Do_nothing()
        {
            const string code = @"hello
world";

            var target = new Developer(new DoNothing());

            Assert.Equal(code, target.Code(code, "toto"));
        }
    }
}